import { observable, configure, action } from 'mobx';

/*
 * mobx 严格模式设置
 * "never" (默认): 可以在任意地方修改状态
 * "observed": 所有状态都需要通过动作进行更改,异步也要通过动作更改
 * "always": 状态始终需要通过动作来更新,异步也要通过动作更改(实际上还包括创建)。
 */
configure({ enforceActions: 'observed' });

class Global {
  @observable loading = false;

  @observable loadingTip = null;

  @observable menus = [];

  @action showLoading(tip = null) {
    this.loading = true;
    this.loadingTip = tip;
  }

  @action hideLoading() {
    this.loading = false;
    this.loadingTip = null;
  }

  @action setMenus(menus) {
    this.menus = menus;
  }

  @action getMenus() {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        const menus = [
          {
            path: '/about',
            icon: ''
          }
        ];
        this.setMenus(menus);
        resolve(menus);
      }, 1500);
    });
  }
}
export default new Global();
